//
//  TuijianController.m
//  Ten
//
//  Created by 韦显光 on 2018/8/26.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "TuijianController.h"
#import "companyCell.h"
@interface TuijianController ()
{
    int page;
    NSMutableArray*mary;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;

@end

@implementation TuijianController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tbv.separatorColor=[UIColor clearColor];
    _tbv.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        page=0;
        mary=[NSMutableArray array];
        [self loaddata];
    }];
    
    [_tbv.mj_header beginRefreshing];
    // Do any additional setup after loading the view.
}
-(void)loaddata
{
    [FuncPublic getData:self parameters:@{@"page":[NSString stringWithFormat:@"%d",page]} RequestUrl:XgetBrandCompany success:^(NSDictionary *acountInfo) {
        [_tbv.mj_header endRefreshing];
        [_tbv.mj_footer endRefreshing];
        NSArray*tempary=acountInfo[@"companys"];
    
        if (tempary.count) {
            [mary addObjectsFromArray:tempary];
            _tbv.mj_footer=[MJRefreshAutoFooter footerWithRefreshingBlock:^{
                page++;
                [self loaddata];
            }];
        }else
        {
            _tbv.mj_footer=nil;
        }
        
        
        
        [_tbv reloadData];
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  mary.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    companyCell*cell=[companyCell CellWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setBackgroundColor:indexPath.row%2==0?WXG_Color(245, 245, 245):[UIColor whiteColor]];
    [cell Cellinit:mary[indexPath.row]];
    return cell;
    

}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([_type isEqualToString:@"choses"]) {
        self.completion(mary[indexPath.row]);
        [self.navigationController popViewControllerAnimated:YES];
    }else
    {
        [MyUtils collviewSelidex:@"公司详情" toVc:self andShopInfo:mary[indexPath.row]];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
